package cn.com.yusys.yusp.message.service.message.mq.rabbitmq;


import org.springframework.amqp.AmqpException;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.core.MessagePostProcessor;
import org.springframework.amqp.rabbit.core.RabbitTemplate;

import cn.com.yusys.yusp.message.service.message.mq.MessageQueueConstants;
import cn.com.yusys.yusp.message.service.message.mq.MessageSender;

public class RabbitMQMessageSender implements MessageSender {
	private RabbitTemplate rabbitTemplate;
	
	public RabbitMQMessageSender(RabbitTemplate rabbitTemplate){
		 this.rabbitTemplate = rabbitTemplate;
	}
	
	@Override
	public void sendMessage(String message,int priority) {
		MessagePostProcessor processor = new MessagePostProcessor() {
			@Override
			public Message postProcessMessage(Message message) throws AmqpException {
				message.getMessageProperties().setPriority(priority);
				return message;
			}
		};
		rabbitTemplate.convertAndSend("",MessageQueueConstants.MESSAGE_QUEUE, message, processor);
	}
	
	@Override
	public void sendDelayMessage(String message,int priority) {
		MessagePostProcessor processor = new MessagePostProcessor() {
			@Override
			public Message postProcessMessage(Message message) throws AmqpException {
				message.getMessageProperties().setPriority(priority);
				return message;
			}
		};
		rabbitTemplate.convertAndSend("",MessageQueueConstants.MESSAGE_DELAY_QUEUE, message, processor);
	}
	
}
